package com.traffic.service.impl;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.service.IService;
import com.traffic.entity.Feedback;
import com.traffic.mapper.FeedbackMapper;
import com.traffic.service.FeedbackService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;
import java.util.Map;


@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements FeedbackService {

    @Autowired
    private FeedbackMapper feedbackMapper;

    @Override
    public List<Feedback> searchByKeywordsAndTime(int type,String startDate,String endDate) {

        QueryWrapper<Feedback> wrapper = new QueryWrapper<>();
        if (type!=0) {
            wrapper.eq("type", type).and(StringUtils.isNotBlank(startDate)
                            && StringUtils.isNotBlank(endDate),
                    dateSql -> dateSql.ge("create_time", startDate)
                            .apply("create_time <= DATE_ADD({0}, INTERVAL 1 DAY)", endDate));

        }else{
            wrapper.like("type", "").and(StringUtils.isNotBlank(startDate)
                            && StringUtils.isNotBlank(endDate),
                    dateSql -> dateSql.ge("create_time", startDate)
                            .apply("create_time <= DATE_ADD({0}, INTERVAL 1 DAY)", endDate));

        }
        List<Feedback> feedbacks = feedbackMapper.selectList(wrapper);
        return feedbacks;
    }
}
